<template>
	<view class="beijingse">
		<header-top :messageInfo="{typeFlag:false,message:'分类',liner:false}"></header-top>
		<view class="mainpadding">
			<!-- 输入框 -->
			<view class="flexleft shuruk" @click="tzsousuo">
				<view class="sousuo margin_right2"></view>
				<input type="text" placeholder="请输入你要搜索的内容" :disabled="true">
			</view>
		</view>
		<!-- 内容 -->
		<view class="leftclass_box">
			<!--左边侧边栏 -->
			<view class="leftclass">
				<view :class="index==current?'itemlistfocus':'itemlist'" v-for="(item,index) in fllist" :key="item.id" @click="change(index,item.id)">
					<view :class="index==current?'line':'lines'" ></view>
					<view :class="index==current?'itenlisttextfocus':'itenlisttext'">{{item.name}}</view>
				</view>
			</view>
			<!-- 右边内容 -->
			<view class="rightcontent ffffff">
				<view class="secondaryclass">
					<view class="kym" v-if="list.data.length==0">
						<image src="../../static/image/system/zwsp.png" mode=""></image>
					</view>
					<view class="flexleft margin_top" v-for="item in list.data" :key="item.id" @click="todetail(item.id)">
						<view class="shilitu margin_right2">
							<image :src="item.image_text" mode=""></image>
						</view>
						<view class="rtbox">
							<view class="ershiliu">{{item.name}}</view>
							<view class="flexbetween" style="margin-top: 60rpx;">
								<view class="huangsetext">￥{{item.price}}</view>
								<view class="gouwuche" @click.stop="joincart(item.id)"></view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				fllist:[],
				current:0,
				page:1,
				limit:10,
				list:{
					data:[],
				},
				orderbyType:0,
				key:'',//关键字
				type:'',
			}
		},
		onLoad() {
			this.getfenlei();
		},
		methods: {
			joincart(id){
				let _this = this;
				httpRequest.request('api/cart/add','POST',{
					goods_id:id,
					num:1,
				}).then(res => {
					httpRequest.toast(res.msg);
				})
			},
			todetail(id){
				uni.navigateTo({
					url:'/pages/homepage/shangpinxq?id=' + id,
				})
			},
			change(i,id){
				this.current = i;
				this.type = id;
				this.getdata();
			},
			getdata(isPage,page){
				let _this = this;
				console.log(_this.type,"_this.type值")
				httpRequest.request('api/goods/goodslist','POST',{
					page:page||1,
					limit:_this.limit,
					orderby:_this.type==0?1:0,
					keywords:_this.key,
					goods_category_id:_this.type==0?"":_this.type,
					type:0,
				}).then(res => {
					if(res.code == 1){
						let resList = res.data.data;
						if (isPage == true) {
							_this.list.data.push(...resList);
						} else {
							_this.list = res.data
							_this.list.data = resList;
						}
					}
				})
			},
			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.total <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.getshoplist(true, page);
			},
			getfenlei(){
				let _this = this;
				httpRequest.request('api/goods/goodsCategory','POST',{
					limit:100,
				}).then(res => {
					if(res.code == 1){
						_this.type = 0;
						_this.fllist = res.data;
						this.fllist.unshift({
							name:"热门爆款",
							id:0
						})
						this.getdata();
					}
				})
			},
			// 跳转搜索页面
			tzsousuo() {
				uni.navigateTo({
					url: '/pages/homepage/sousuo'
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.kym {
		margin: 250rpx auto 0;
		width: 319rpx;
		height: 267rpx;
	
		image {
			width: 100%;
			height: 100%;
		}
	}
	
	.rtbox {
		// width: 100%;
		flex: 6;
	}

	.header {
		/*#ifdef MP-WEIXIN || APP-PLUS*/
		height: 150rpx;
		padding: 80rpx 30rpx 30rpx;
		/*#endif*/
		width: 100%;
		background-color: #fff;
		box-sizing: border-box;
	}

	.toububox {
		background-size: cover;
		display: flex;
		align-items: center;
		position: fixed;
		z-index: 10;
		left: 0;
		top: 0;
		/*#ifdef MP-WEIXIN || APP-PLUS*/
		padding: 120rpx 30rpx 30rpx;
		/*#endif*/
		width: 100%;
		background-color: #fff;
		box-sizing: border-box;
	}

	.huangsetext {
		font-size: 20rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #FF8110;
	}

	.secondaryclass {
		width: 100%;
		margin-top: 0;
		background-color: #fff;
		border-radius: 10rpx;
		box-sizing: border-box;
	}

	.rightcontent {
		width: 100%;
		padding: 0rpx 30rpx 185rpx 190rpx;
		box-sizing: border-box;
	}

	.ershiliu {
		font-size: 26rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #333333;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
		width: 340rpx;
	}

	.shilitu {
		width: 134rpx;
		height: 128rpx;
		border-radius: 14rpx;

		image {
			width: 100%;
			height: 100%;
			border-radius: 14rpx;
		}
	}

	// 侧边栏
	// 未选中背景色
	.itemlist {
		padding: 20rpx 16rpx;
		height: 60rpx;
		display: flex;
		align-items: center;
		background: #F9F9F8;
	}

	// 选中背景色
	.itemlistfocus {
		padding: 20rpx 16rpx;
		height: 60rpx;
		display: flex;
		align-items: center;
		background-color: #ffffff;
	}

	.line {
		width: 10rpx;
		border-radius: 10rpx;
		height: 60rpx;
		background-color: #F78D2B;
	}

	.lines {
		width: 10rpx;
		border-radius: 10rpx;
		height: 60rpx;
		background-color: #fff;
	}
	// 未选中
	.itenlisttext {
		margin-left: 20rpx;
		text-align: center;
		font-size: 28rpx;
		color: #333;
		width: 120rpx;
	}

	// 选中
	.itenlisttextfocus {
		margin-left: 10rpx;
		text-align: center;
		font-size: 28rpx;
		color: #F78D2B;
		width: 120rpx;
	}

	.leftclass {
		top: 313rpx;
		position: fixed;
		left: 0;
		height: calc(100vh - 176rpx - 138rpx);
		overflow-y: auto;
		background: #F9F9F8;
	}

	.leftclass_box {
		min-height: calc(100vh - 176rpx - 138rpx);
		display: flex;
	}

	.inputs {
		padding: 10rpx 30rpx;
		box-sizing: border-box;
		width: 100%;
		border-radius: 30rpx;
		border: 1rpx solid #EF8933;
	}
</style>
